package com.gjzhao.fmmall.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.gjzhao.fmmall.beans.Users;
import com.gjzhao.fmmall.dao.UserCheckMapper;
import com.gjzhao.fmmall.service.UserCheckService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

/**
 * @Description: 查询用户
 * @Author: gjzhao
 * @Date Created in 2022-02-12 3:14 下午
 */
@Service
public class CheckUserServiceImpl implements UserCheckService {

    @Autowired
    private UserCheckMapper userCheckMapper;

    @Override
    public Users checkUser(String username) {

        //构建条件查询用户
        Example example = new Example(Users.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("username", username);
        List<Users> usersList = userCheckMapper.selectByExample(example);

        //封装返回结果
        if (CollectionUtil.isNotEmpty(usersList)) {
            return usersList.get(0);
        } else {
            return null;
        }

    }
}
